package cn.mabach.modules.generator.controller;

import cn.mabach.DTO.PageUtils;
import cn.mabach.DTO.RS;
import cn.mabach.common.utils.R;
import cn.mabach.modules.generator.feign.ReturnOrderItemServiceFeign;
import cn.mabach.order.entity.ReturnOrderItemEntity;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 * 
 *
 * @author chenshun
 * @email 176468159@qq.com
 * @date 2019-12-19 22:31:14
 */
@RestController
@RequestMapping("generator/returnorderitem")
public class ReturnOrderItemController {
    @Autowired
    private ReturnOrderItemServiceFeign returnOrderItemService;

    /**
     * 列表
     */

    @RequestMapping("/list")
    @RequiresPermissions("generator:returnorderitem:list")
    public R list(@RequestParam Map<String, Object> params){
        RS<PageUtils> res = returnOrderItemService.queryPage(params);
        if (res.getCode()!=200){
            return R.error();
        }

        return R.ok().put("page", res.getData());
    }


    /**
     * 信息
     */

    @RequestMapping("/info/{id}")
    @RequiresPermissions("generator:returnorderitem:info")
    public R info(@PathVariable("id") Long id){
        RS<ReturnOrderItemEntity> res = returnOrderItemService.getByIdE(id);
        if (res.getCode()!=200){
            return R.error();
        }

        return R.ok().put("returnOrderItem", res.getData());
    }



    /**
     * 保存
     */

    @RequestMapping("/save")
    @RequiresPermissions("generator:returnorderitem:save")
    public R save(@RequestBody ReturnOrderItemEntity returnOrderItem){
        RS res = returnOrderItemService.saveE(returnOrderItem);
        if (res.getCode()!=200){
            return R.error();
        }

        return R.ok();
    }

    /**
     * 修改
     */


    @RequestMapping("/update")
    @RequiresPermissions("generator:returnorderitem:update")
    public R update(@RequestBody ReturnOrderItemEntity returnOrderItem){
        RS res = returnOrderItemService.updateByIdE(returnOrderItem);
        if (res.getCode()!=200){
            return R.error();
        }

        return R.ok();
    }

    /**
     * 删除
     */

    @RequestMapping("/delete")
    @RequiresPermissions("generator:returnorderitem:delete")
    public R delete(@RequestBody Long[] ids){
        RS res = returnOrderItemService.removeByIdsE(Arrays.asList(ids));
        if (res.getCode()!=200){
            return R.error();
        }

        return R.ok();
    }

}
